<?php

namespace App\Model;

use EasySwoole\ORM\AbstractModel;

/**
 * Class ActivitySignModel
 * Create With Automatic Generator
 * @property $id
 * @property $user_id
 * @property $activity_id
 * @property $sign_datetime
 * @property $create_time
 */
class ActivitySignModel extends AbstractModel
{
    protected $tableName = 'bee_activity_sign001';

    protected $primaryKey = 'id';

    protected $autoTimeStamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = false;

    /**
     * 设置分表名
     * @param int $userId
     * @return ActivitySignModel|string
     * @throws \EasySwoole\ORM\Exception\Exception
     */
    public function changeTableName(int $userId = 1)
    {
        $mod = $userId % 100;
        $trueTableName = 'bee_activity_apply' . str_pad($mod, 3, "0", STR_PAD_LEFT);
        return $this->tableName($trueTableName);
    }

    /**
     * 通过其他条件查找信息
     * @param string $field
     * @return ActivityApplyModel|null
     * @throws \EasySwoole\Mysqli\Exception\Exception
     * @throws \EasySwoole\ORM\Exception\Exception
     * @throws \Throwable
     */
    public function getOneByUser($field = '*', $where = ''): ?ActivitySignModel
    {
        /** @var ActivitySignModel $info */
        $info = $this->field($field)->where($where)->get();
        return $info;
    }
}